package com.vmss.cspider;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;


public class SpiderApp {
	
	public static void main( String args[]) throws Exception
	{
		System.out.println("YES");
		//DBUtil.getConnection();
		
		CPICInsurance cpic= new CPICInsurance();
		cpic.startCatch();
		
		//Properties requestProperties = new Properties();  
		
		// 模拟浏览器信息   
		//requestProperties.put("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; TencentTraveler ; .NET CLR 1.1.4322)"); 
		
//		Properties formRequest = new Properties();
//		formRequest.setProperty("_action", "fastCalculation");
//		formRequest.setProperty("cityCode", "110100");
//		formRequest.setProperty("claim", "0");
//		formRequest.setProperty("contractExpiredMonth", "2013-04-18");
//		formRequest.setProperty("isCpic", "0");
//		formRequest.setProperty("isNewCar", "1");
//		formRequest.setProperty("mobile", "15110258837");
//		formRequest.setProperty("provinceCode", "110000");
//		formRequest.setProperty("registerDate", "2012-04-01");
//		formRequest.setProperty("seatCout", "5");
//		formRequest.setProperty("vehiclePrice", "12");
//		//formRequest.setProperty("sourceName", "12");
//		
//		String urlString = "http://www.cpic.com.cn/cpicweb/view/customer/personal/vehicle/SimpleChinaFastCalculationViewNew.jsp";
//		
//		StringBuffer pStringBuffer = NetUtils.requestPostForm(urlString, formRequest);
//		System.out.println( pStringBuffer ); 
//		
//		String pstr = "\"([^\"]+)\":([^,]+),";
//		Pattern pattern = Pattern.compile(pstr);
//		Matcher matcher = pattern.matcher(pStringBuffer.toString());
//		while( matcher.find())
//		{	
//			if(matcher.groupCount() == 2)
//			{
//				String s1 = matcher.group(1);
//				String s2 = matcher.group(2);
//				System.out.print(s1);
//				System.out.println(s2);
//			}
//		}



	}
	
	
//	public static void main(String[] args) {  
//        try {  
//            java.net.URL url = new java.net.URL("http://www.pingan.com/ebusiness/auto/to-simple-accept-utf8.do");  
//            java.net.URLConnection conn = url.openConnection();  
//            conn.connect();  
//            System.out.println("1" + conn.getContentType());  
//            System.out.println("2" + conn.getContentEncoding());//获取页面编码  
//            System.out.println("3" + conn.getContentLength());  
//            System.out.println("4" + conn.getDate());  
//            System.out.println("5" + conn.getExpiration());  
//            System.out.println("6" + conn.getLastModified());  
//            StringBuffer contentBuffer = new StringBuffer();  
//            java.io.InputStream is = conn.getInputStream();  
//            //java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(is, conn.getContentEncoding()));  
//            java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(is));  
//            String inputLine = null;  
//            while ((inputLine = reader.readLine()) != null) {  
//                contentBuffer.append(inputLine);  
//                contentBuffer.append("\n");  
//            }  
//            is.close();  
//            System.out.println("" + contentBuffer.toString());  
//        } catch (java.net.MalformedURLException e) {  
//            e.printStackTrace();  
//        } catch (java.io.IOException e) {  
//            e.printStackTrace();  
//        }  
//		sendPost( "http://www.pingan.com/ebusiness/auto/to-simple-accept-utf8.do","");
//    }
	
	 public static String sendPost(String url,String param)
	 {
	  String result="";
	  try{
	   URL httpurl = new URL(url);
	   HttpURLConnection httpConn = (HttpURLConnection)httpurl.openConnection();      
	   httpConn.setDoOutput(true);
	   httpConn.setDoInput(true);
	   PrintWriter out = new PrintWriter(httpConn.getOutputStream());
	   out.print(param);
	   out.flush();
	   out.close();
	   BufferedReader in = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
	   String line;
	   while ((line = in.readLine())!= null)
	   {
	    result += line;
	   }
	   in.close();
	  }catch(Exception e){
	   System.out.println("没有结果！"+e);
	  }
	  
	  System.out.println(result.toString());
	  return result;
	 }
}
